package test;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/11/18.
 */
public class IpBehavior {
    public static void main(String[] args) throws IOException {
//        List<String> ipList = getIpList();
//        for(String ip : ipList){
//            writeContents(ip);
//        }
        writeHack("register/sendSmsCode");
    }

    private static void writeHack(String key) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\admin\\Downloads\\result2.log"));
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\admin\\Downloads\\result.log"));
        String line = null;
        while((line=reader.readLine()) != null){
            if(line.contains(key) || "=====================================================================".equals(line)){
                writer.write(line);
                writer.newLine();
            }
        }
        reader.close();
        writer.close();
    }

    private static void writeContents(String ip) throws IOException {
        BufferedWriter writer = new BufferedWriter(new FileWriter("C:\\Users\\admin\\Downloads\\result.log",true));
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\admin\\Downloads\\vv-sso.access.log"));
        String line = null;
        while((line=reader.readLine()) != null){
            if(line.contains(ip)){
                writer.write(line);
                writer.newLine();
            }
        }
        writer.newLine();
        writer.write("=====================================================================");
        writer.newLine();
        reader.close();
        writer.close();
    }

    private static List<String> getIpList() throws IOException {
        List<String> ipList = new ArrayList<>();
        BufferedReader reader = new BufferedReader(new FileReader("C:\\Users\\admin\\Downloads\\aa.txt"));
        String line = null;
        while((line=reader.readLine()) != null){
            String ip = line.substring(0,line.indexOf("\t"));
            ipList.add(ip);
        }
        reader.close();
        return ipList;
    }
}
